package com.ethan.hateoas.controller;

import com.ethan.hateoas.vo.UserVo;
import org.springframework.hateoas.server.core.ControllerEntityLinks;
import org.springframework.hateoas.server.mvc.ControllerLinkBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping("get")
    public Object user(){
        UserVo userVo = new UserVo("张三");
        //添加自身地址信息
        userVo.add(linkTo(methodOn(UserController.class).user()).withSelfRel()).
                //添加额外地址信息
                add(linkTo(methodOn(UserController.class).info(1L)).withRel("info"));
        return userVo;
    }
    @GetMapping("info/{id}")
    public Object info(@PathVariable Long id){
        return "info"+id;
    }
}
